package com.inspinia.base.web.controller;

import com.inspinia.config.common.config.SystemConfig;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 通用映射
 */
@Controller
public class PageController {

    @RequestMapping("index")
    public String index() {
        return "redirect:/home";
    }

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String toLoginHtml(Model model,String kickout,String username,String pwd,String forwardUrl) {
        model.addAttribute("kickout", kickout);
        model.addAttribute("username", username);
        model.addAttribute("pwd", pwd);
        model.addAttribute("forwardUrl", forwardUrl);
        return "login";
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String root(Model model) {
        return "redirect:/home";
    }

    @RequestMapping(value = "common/error/{code}", method = RequestMethod.GET)
    public String error(@PathVariable int code) {
        return "common/error/" + code;
    }

    @RequestMapping(value = "home",method = RequestMethod.GET)
    public String home(Model model) {
        loadIndexSetting(model);
        try {
        } catch (Exception e) {
            //不做处理
        }
        return "home";
    }

    /**
     * swagger 接口
     */
    @RequestMapping("swagger")
    public String SwaggerController(){
        return "swagger/index";
    }

    /**
     * sitemesh装饰器的默认装饰器地址,由于默认装饰器中使用了freemarker标签,因此需要经过freemarker解析才能使用。
     *
     * @return
     */
    @RequestMapping(value = "decorators/default")
    public String defaultDecorator() {
        return "decorators/default";
    }

    /**
     * 不用装饰的话，在html head中写上    <meta name="decorator" content="/decorators/blank"/>
     * 无需装饰,空模板
     * @return
     */
    @RequestMapping(value = "decorators/blank")
    public String defaultDecoratorBlank() {
        return "decorators/default-blank";
    }

    @RequestMapping("unauthorized")
    public String unauthorized() {
        return "unauthorized";
    }

    /**
     * 主页信息
     */
    public static void loadIndexSetting(Model model) {
        model.addAttribute("pageFoot", SystemConfig.systemPagefoot);
        model.addAttribute("indexPageTitle", SystemConfig.systemIndexPageTitle);
        model.addAttribute("indexTitleName", SystemConfig.systemIndexTitleName);
        model.addAttribute("version", SystemConfig.version);
        model.addAttribute("isShowLogo", SystemConfig.isShowLogo);
    }
}
